{% extends "base.html" %}

{% block title %}Basic Form - Flask Forms Demo{% endblock %}

{% block content %}
<h2>Basic Form Handling</h2>

<div class="row">
    <div class="col-md-6">
        <form method="POST">
            <div class="form-field">
                <label for="name" class="form-label">Name</label>
                <input type="text" class="form-control" id="name" name="name" 
                       value="{{ request.form.get('name', '') }}" required>
                {% if errors and errors.name %}
                    <div class="text-danger">{{ errors.name }}</div>
                {% endif %}
                <div class="form-text">Enter your full name</div>
            </div>
            
            <div class="form-field">
                <label for="email" class="form-label">Email</label>
                <input type="email" class="form-control" id="email" name="email" 
                       value="{{ request.form.get('email', '') }}" required>
                {% if errors and errors.email %}
                    <div class="text-danger">{{ errors.email }}</div>
                {% endif %}
                <div class="form-text">Enter a valid email address</div>
            </div>
            
            <div class="form-field">
                <label for="age" class="form-label">Age</label>
                <input type="number" class="form-control" id="age" name="age" 
                       value="{{ request.form.get('age', '') }}" min="1" max="120">
                {% if errors and errors.age %}
                    <div class="text-danger">{{ errors.age }}</div>
                {% endif %}
                <div class="form-text">Enter your age (1-120)</div>
            </div>
            
            <div class="form-field">
                <label for="bio" class="form-label">Bio</label>
                <textarea class="form-control" id="bio" name="bio" rows="3">{{ request.form.get('bio', '') }}</textarea>
                {% if errors and errors.bio %}
                    <div class="text-danger">{{ errors.bio }}</div>
                {% endif %}
                <div class="form-text">Tell us about yourself (optional)</div>
            </div>
            
            <div class="form-field">
                <label class="form-label">Preferences</label>
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" id="newsletter" name="preferences" value="newsletter"
                           {% if 'newsletter' in request.form.getlist('preferences') %}checked{% endif %}>
                    <label class="form-check-label" for="newsletter">Subscribe to newsletter</label>
                </div>
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" id="notifications" name="preferences" value="notifications"
                           {% if 'notifications' in request.form.getlist('preferences') %}checked{% endif %}>
                    <label class="form-check-label" for="notifications">Enable notifications</label>
                </div>
            </div>
            
            <div class="form-field">
                <label class="form-label">Account Type</label>
                <div class="form-check">
                    <input class="form-check-input" type="radio" name="account_type" id="personal" value="personal"
                           {% if request.form.get('account_type') == 'personal' %}checked{% endif %}>
                    <label class="form-check-label" for="personal">Personal</label>
                </div>
                <div class="form-check">
                    <input class="form-check-input" type="radio" name="account_type" id="business" value="business"
                           {% if request.form.get('account_type') == 'business' %}checked{% endif %}>
                    <label class="form-check-label" for="business">Business</label>
                </div>
                {% if errors and errors.account_type %}
                    <div class="text-danger">{{ errors.account_type }}</div>
                {% endif %}
            </div>
            
            <button type="submit" class="btn btn-primary">Submit</button>
            <a href="{{ url_for('index') }}" class="btn btn-secondary">Back</a>
        </form>
    </div>
    
    <div class="col-md-6">
        <div class="card">
            <div class="card-header">
                <h5>Form Data</h5>
            </div>
            <div class="card-body">
                {% if form_data %}
                    <h6>Submitted Data:</h6>
                    <pre>{{ form_data|pprint }}</pre>
                {% else %}
                    <p>Submit the form to see the data here.</p>
                {% endif %}
            </div>
        </div>
        
        <div class="card mt-3">
            <div class="card-header">
                <h5>About Basic Form Handling</h5>
            </div>
            <div class="card-body">
                <p>This example demonstrates manual form handling without external libraries:</p>
                <ul>
                    <li>Accessing form data with <code>request.form</code></li>
                    <li>Manual validation with custom functions</li>
                    <li>Preserving form data on validation errors</li>
                    <li>Displaying validation errors</li>
                </ul>
            </div>
        </div>
    </div>
</div>
{% endblock %}